import os
import random

# 输出目录
output_dir = r"C:\Users\ASUS\Desktop\2025-BBUCPC\2025校赛出题\A题\A_inputs"
os.makedirs(output_dir, exist_ok=True)

random.seed(42)

tests = []
# 30% 小规模、70% 大规模
small_remain = 6
large_remain = 14
# 两个分支各 10 个
branch1_remain = 10  # t < m+1
branch2_remain = 10  # t >= m+1

def gen_small():
    # n, m, k 都比较小，sum(a) <= 2e9 以下
    n = random.randint(1, 1000)
    m = random.randint(0, 1000)
    k = random.randint(1, 1000)
    a = [random.randint(1, 100) for _ in range(n)]
    return n, m, k, a

def gen_large():
    # n 接近 1e5，a_i 接近 1e9，sum(a) 可达 1e14
    n = random.randint(50000, 100000)
    m = random.randint(50000, 100000)
    k = random.randint(10**8, 10**9)
    a = [random.randint(10**8, 10**9) for _ in range(n)]
    return n, m, k, a

while len(tests) < 20:
    # 决定用 small 还是 large
    if small_remain > 0 and large_remain > 0:
        use_small = random.random() < small_remain / (small_remain + large_remain)
    else:
        use_small = (small_remain > 0)
    if use_small:
        n, m, k, a = gen_small()
    else:
        n, m, k, a = gen_large()

    total = sum(a)
    t = total // k
    # 判断分支
    if t < m + 1:
        branch = 1
    else:
        branch = 2

    # 看这个分支是否还需要
    if branch == 1 and branch1_remain > 0:
        branch1_remain -= 1
    elif branch == 2 and branch2_remain > 0:
        branch2_remain -= 1
    else:
        # 当前分支已满，丢弃重来
        continue

    # 标记 small/large 配额
    if use_small:
        small_remain -= 1
    else:
        large_remain -= 1

    tests.append((n, m, k, a))

# 写入文件 1.in ~ 20.in
for idx, (n, m, k, a) in enumerate(tests, start=1):
    fn = os.path.join(output_dir, f"{idx}.in")
    with open(fn, "w") as f:
        f.write(f"{n} {m} {k}\n")
        f.write(" ".join(map(str, a)))
    print(f"Written {fn}")

print("全部 20 个测试点已生成。")
